#include "Clock.h"
#include "Color.h"
#include "Highscore.h"
#include "Land.h"
#include "LineSegment.h"
#include "Map.h"
#include "MapBacktrack.h"
#include "MapSolver.h"
#include "Move.h"
#include "Point.h"
#include "Properties.h"
#include "Province.h"
#include "Score.h"
#include <iostream>

int main(int argc, char *argv[])
{
	if (argc < 2)
	{
		std::cout << "Usage: " << argv[0] << " mapfilename" << std::endl;


		return -1;
	}

	std::string filename = argv[1];
	unsigned int i = 1;
	Map map;
	Properties properties;
	Move move;

	std::cout << "Loading " << filename << std::endl;
	
	if(!map.LoadFromFile(filename))
	{
		std::cout << "Could not load map." << std::endl;
		return -1;
	}
	std::cout << "Map loaded succesfully." << std::endl << std::endl;

	try
	{
		MapBacktrack *backtrack = new MapBacktrack(map, properties);

		backtrack->Initialize();

		while(!(map.IsCompleted()))
		{
			move = backtrack->NextMove();

			map.SetColor(move.GetLand(), move.GetProvince(), move.GetColor());
			std::cout << "step " << i << " Coloring: " << move.ToString() << std::endl;
			i++;
		}

		std::cout << std::endl << "Map Completed" << std::endl;
	} catch(...)
	{
		std::cout << "An internal error happened while trying to solve the map";
	}

	return 0;
}

